package server.modules.generator.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import server.common.utils.PageUtils;
import server.common.utils.Query;

import server.modules.generator.dao.QiandaoDao;
import server.modules.generator.entity.MeetingEntity;
import server.modules.generator.entity.PointEntity;
import server.modules.generator.entity.ProjectEntity;
import server.modules.generator.entity.QiandaoEntity;
import server.modules.generator.service.MeetingService;
import server.modules.generator.service.QiandaoService;
import server.modules.sys.entity.SysUserEntity;
import server.modules.sys.service.SysUserService;


@Service("qiandaoService")
public class QiandaoServiceImpl extends ServiceImpl<QiandaoDao, QiandaoEntity> implements QiandaoService {
    @Autowired
    SysUserService sysUserService;
    @Autowired
    MeetingService meetingService;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Long toUser = (Long) params.get("toUser");
        IPage<QiandaoEntity> page = this.page(
                new Query<QiandaoEntity>().getPage(params),
                new QueryWrapper<QiandaoEntity>()
                        .eq(null!=toUser,"create_user",toUser)
                        .orderByDesc("created_time")
        );

        for (QiandaoEntity sing : page.getRecords()) {
            SysUserEntity sysUserEntity = sysUserService.getById(sing.getCreateUser());
            if (null != sysUserEntity)
                sing.setCreateUserName(sysUserEntity.getShowname());
            else
                sing.setCreateUserName("未配置");
            MeetingEntity meetingEntity = meetingService.getById(sing.getMeetid());
            if (null != meetingEntity)
                sing.setMeetName(meetingEntity.getTitle());

            else
                sing.setMeetName("未配置");


        }

        return new PageUtils(page);
    }

}